<?php
/**
 * Created by PhpStorm.
 * User: johnny
 * Date: 17-7-17
 * Time: 下午8:17
 */

namespace common\actions;


use yii\base\Action;
use Yii;
use yii\base\Exception;

class AttachmentDeleteAction extends Action
{
    public $deleteAttachment;
    public $uuid = 'uuid';
    public $path = 'path';
    public $field;
    public function init()
    {
        if(!is_array($this->deleteAttachment) || !is_callable($this->deleteAttachment)) {
            throw new Exception('invalid delete attachment');
        }
    }

    public function run() {
        $uuid = Yii::$app->request->get($this->uuid);
        $path = Yii::$app->request->get($this->path);
        return call_user_func_array($this->deleteAttachment, [$uuid, $path, $this->field ? $this->field  : 'path']);
    }
}